

#include <ast.h>

ASTNode::ASTNode ()
{
  _children.clear();
  _parent = 0;
}

void ASTNode::Add(ASTNode *base)
{
  if (!base)
    {
      return;
    }

  _children.push_back(base);
  base->_parent = this;
}

void ASTNode::Reconstruct()
{
  for (list<ASTNode*>::iterator it = _children.begin();
       it != _children.end();
       ++it)
    {
      ASTNode* base = *it;
      base->Reconstruct();
    }
}

VariableDeclaration::VariableDeclaration(string type, string name)
  : ASTNode ()
  , _type (type)
  , _name (name)
{

}

string VariableDeclaration::GetType() const
{
  return _type;
}

string VariableDeclaration::GetName() const
{
  return _name;
}


void VariableDeclaration::Reconstruct()
{
  printf ("%s %s", _type.c_str(), _name.c_str());
  ASTNode::Reconstruct();
  printf (";");
}
